/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.woupla.model;

import java.io.Serializable;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Dimitri Lebel
 */
@Entity
@Table(name = "category")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Category.findAll", query = "SELECT c FROM Category c"),
    @NamedQuery(name = "Category.findById", query = "SELECT c FROM Category c WHERE c.id = :id"),
    @NamedQuery(name = "Category.findByParent", query = "SELECT c FROM Category c WHERE c.parent = :parent"),
    @NamedQuery(name = "Category.findByParentLabel", query = "SELECT c FROM Category c WHERE c.parent.label = :parent"),
    @NamedQuery(name = "Category.findParentIsNull", query = "SELECT c FROM Category c WHERE c.parent is null"),
    @NamedQuery(name = "Category.findByLabel", query = "SELECT c FROM Category c WHERE c.label = :label")})
public class Category implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = -3361901270970125076L;
	@Id
    @Basic(optional = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;
    @Column(name = "label")
    private String label;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "parent")
    private Collection<Category> categoryCollection;
    @JoinColumn(name = "parent", referencedColumnName = "id")
    @ManyToOne
    private Category parent;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
    private Collection<ProduitGenerique> produitGeneriqueCollection;

    public Category() {
    }

    public Category(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getLabel() {
        return label;
    }

    public void setLabel(String label) {
        this.label = label;
    }

    @XmlTransient
    public Collection<Category> getCategoryCollection() {
        return categoryCollection;
    }

    public void setCategoryCollection(Collection<Category> categoryCollection) {
        this.categoryCollection = categoryCollection;
    }

    public Category getParent() {
        return parent;
    }

    public void setParent(Category parent) {
        this.parent = parent;
    }

    @XmlTransient
    public Collection<ProduitGenerique> getProduitGeneriqueCollection() {
        return produitGeneriqueCollection;
    }

    public void setProduitGeneriqueCollection(Collection<ProduitGenerique> produitGeneriqueCollection) {
        this.produitGeneriqueCollection = produitGeneriqueCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Category)) {
            return false;
        }
        Category other = (Category) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "javaapplication1.Category[ id=" + id + " ]";
    }
    
}
